dnl libustream: User-space stackable streams
dnl @(#) $Id: configure.ac 3 2009-02-20 22:59:30Z mo@ilaven.net $

dnl Copyright (c) 2002, 2008 Mo McRoberts.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl 1. Redistributions of source code must retain the above copyright
dnl    notice, this list of conditions and the following disclaimer.
dnl 2. Redistributions in binary form must reproduce the above copyright
dnl    notice, this list of conditions and the following disclaimer in the
dnl    documentation and/or other materials provided with the distribution.
dnl 3. The names of the author(s) of this software may not be used to endorse
dnl    or promote products derived from this software without specific prior
dnl    written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
dnl INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
dnl AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
dnl AUTHORS OF THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
dnl TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

dnl Copyright (c) 2007 James Antill
dnl
dnl Permission is hereby granted, free of charge, to any person
dnl obtaining a copy of this software and associated documentation
dnl files (the "Software"), to deal in the Software without
dnl restriction, including without limitation the rights to use,
dnl copy, modify, merge, publish, distribute, sublicense, and/or sell
dnl copies of the Software, and to permit persons to whom the
dnl Software is furnished to do so, subject to the following
dnl conditions:
dnl 
dnl The above copyright notice and this permission notice shall be
dnl included in all copies or substantial portions of the Software.
dnl 
dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
dnl EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
dnl OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
dnl NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
dnl HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
dnl WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
dnl OTHER DEALINGS IN THE SOFTWARE.

AC_INIT(libustream, 1.4)
AC_CONFIG_SRCDIR([include/ustream/ustream.h])
AM_INIT_AUTOMAKE([foreign])
AM_MAINTAINER_MODE

CPPFLAGS="$CPPFLAGS -W -Wall -D_REENTRANT -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
export CPPFLAGS

CFLAGS="$CFLAGS -g -O0"
export CFLAGS

AC_PROG_CC
AC_PROG_CXX
AC_PROG_LIBTOOL

JL_WITH_LIBCOM

LIBIRI_CPPFLAGS=''
LIBIRI_LIBS=''
AC_ARG_WITH(libiri-sources, [AS_HELP_STRING([--with-libiri-sources=PATH],[Build against a libiri source tree])],[
dir="`cd \"${withval}\" && pwd`"
AC_MSG_RESULT([building against not-yet-installed libiri sources in ${dir}])
LIBIRI_CPPFLAGS="-I${dir}/include"
LIBIRI_LIBS="${dir}/libiri/libiri.la"
])
AC_SUBST([LIBIRI_CPPFLAGS])
AC_SUBST([LIBIRI_LIBS])

USTR_CPPFLAGS="-DUSTR_CONF_HAVE_64bit_SIZE_MAX=0 -DUSTR_CONF_USE_ASSERT=1 -DUSTR_CONF_USE_EOS_MARK=1"
AC_MSG_CHECKING([for a broken vsnprintf() implementation])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>

#define USE_FMT_1_3 0

static int my_autoconf(const char *fmt, ...)
{
  va_list ap;
  char buf[1] = "";
  int ret = -1;

  va_start(ap, fmt);
  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);

  return (ret);
}
]],[[
  if (my_autoconf("12") == -1)
	{
		return 1;
	}
  return 0;
]])],[broken_vsnprintf=no;USTR_CPPFLAGS="${USTR_CPPFLAGS} -DUSTR_CONF_HAVE_RETARDED_VSNPRINTF=0"],[broken_vsnprintf=yes;USTR_CPPFLAGS="${USTR_CPPFLAGS} -DUSTR_CONF_HAVE_RETARDED_VSNPRINTF=1"])
AC_MSG_RESULT([$broken_vsnprintf])

AC_CHECK_HEADER([stdint.h],[USTR_CPPFLAGS="${USTR_CPPFLAGS} -DUSTR_CONF_HAVE_STDINT_H=1"],[USTR_CPPFLAGS="${USTR_CPPFLAGS} -DUSTR_CONF_HAVE_STDINT_H=0"])

AC_SUBST([USTR_CPPFLAGS])

AC_CONFIG_HEADER([config.h])

AC_CONFIG_FILES([Makefile
include/Makefile
include/ustream/Makefile
libustr/Makefile
modules/Makefile
libustream/Makefile
utils/Makefile
tests/Makefile
])

AC_OUTPUT
